home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #
- # Archive manager for glimpseHTTP
-
- # Location of httpd directory
- $HTTPD_HOME="/usr1/paul/httpd";
- $wwwlib = $HTTPD_HOME . "/wwwlib" ;
-
- # Location of glimpse and glimpseindex, options for glimpseindex
- $GLIMPSE_LOC="/usr/local/bin/glimpse";
- $GLIMPSEIDX_LOC="/usr/local/bin/glimpseindex";
-
- # server administrator name
- $adminname="Paul Klark";
- # server administrator e-mail
- $adminaddress="paul@cs.arizona.edu";
-
- # index template
- $TEMPLATE="$wwwlib/template.bd";
- # description file, we try to find it in every directory
- $DESCFILE=".description";
- # name of the index file
- $HTMLINDEX="ghindex.html";
-
- #
- # no configuration is needed below this line
- #
-
- $config = "$wwwlib/amgr.cfg";
- $narch = 0;
- open(CFG,"<$config") ;
- $defserver = "";
- $next = "00";
- while (<CFG>) {
- chop;
- ($path[$narch],$url[$narch],$title[$narch],
- $script[$narch],$server[$narch],$idxf[$narch],$idxn[$narch])
- = split("\t");
- $defserver = $server[$narch];
- $next = $script[$narch];
- $narch++;
- }
- $deftemplate = "template.bd";
- $defprogram = "aglimpse";
- close(CFG);
- &a_list;
- while ("true") {
- print "(H)elp (E)dit (A)dd (D)elete (P)rint (L)ist (I)ndex (Q)uit\n" ;
- $_ = &read("Enter command","Q");
- /^[qQ]/ && last;
- /^$/ && next;
- ($command,$num) = split;
- if (/^[pedi]/) {
- if ($num !~ /^\d+/) {
- print "This command requires ",
- "a numeric parameter - archive number (0...$#path)\n";
- next;
- }
- if ( $num<0 || $num>$#path ) {
- print "Archive number must be an integer ".
- "between 0 and $#path\n";
- next;
- }
- }
- if (/^[aA]/) {
- &a_add;
- } elsif (/^e/oi) {
- &a_edit($num);
- } elsif (/^d/oi) {
- &a_delete($num);
- } elsif (/^p/oi) {
- &a_print($num);
- } elsif (/^i/oi) {
- &a_index($num);
- } elsif (/^h/oi) {
- &a_help;
- } elsif (/^l/oi) {
- &a_list;
- } else {
- print "Unknown command\n";
- }
- }
- # now save the configuration
- open(CFG,">$config") ;
- for $i (0..$#path) {
- print CFG $path[$i],"\t",$url[$i],"\t",$title[$i],"\t",
- $script[$i],"\t",$server[$i],"\t",$idxf[$i],"\t",$idxn[$i],"\n";
- }
-
- sub read {
- local($prompt,$def) = @_;
- print $prompt,"[",$def,"]:";
- $| = 1;
- $_ = <STDIN>;
- chop;
- return $_?$_:$def;
- }
- sub a_list {
- local($i);
- for $i (0..$#path) {
- print "-" x20,"Archive #",$i,"\n";
- &a_print($i);
- }
- }
- sub a_print {
- local($i) = $_[0];
- print "Disk path :",$path[$i],"\n";
- print "URL path :",$url[$i],"\n";
- print "Title :",$title[$i],"\n";
- print "Script :",$script[$i],"\n";
- print "Server :",$server[$i],"\n";
- print "File per block:",$idxf[$i],"\n";
- print "Index numbers :",$idxn[$i],"\n";
- }
- sub a_edit {
- local($i) = $_[0];
- local($cwd);
- $cwd = `pwd`;
- chop $cwd;
- do {
- $path[$i] = &read("Disk path ",$path[$i]);
- $result = chdir $path[$i];
- if ($result) {
- $path[$i] = `pwd`;
- chop $path[$i];
- } else {
- print "Cannot chdir to $path[$i]: $!\n" unless $result;
- }
- chdir $cwd || die "Cannot chdir back to $cwd: $!\n";
- } until $result;
- $url[$i] = &read("URL path ",$url[$i]);
- $title[$i] = &read("Title ",$title[$i]);
- $script[$i] = &read("Script ",$script[$i]);
- $server[$i] = &read("Server ",$server[$i]);
- $idxf[$i] = &read("File per block",$idxf[$i]);
- $idxn[$i] = &read("Index numbers ",$idxn[$i]);
- }
- sub a_add {
- $#path++;
- $#url++;
- $#title++;
- $#script++;
- $script[$#script] = ++$next;
- $#server++;
- $server[$#server] = $defserver;
- $#idxf++;
- $idxf[$#idxf] = "yes";
- $#idxn++;
- $idxn[$#idxn] = "no";
- &a_edit($#server);
- $defserver = $server[$#server];
- }
- sub a_help {
- system("more $wwwlib/README.amgr");
- }
- sub a_delete {
- local($i) = @_;
- splice(@path,$i,1);
- splice(@url,$i,1);
- splice(@title,$i,1);
- splice(@script,$i,1);
- splice(@server,$i,1);
- splice(@idxf,$i,1);
- splice(@idxn,$i,1);
- }
- sub a_index {
- local($i) = @_;
- local($path,$title);
- $searchurl = $server[$i] . "/cgi-bin/".
- $defprogram . "/" . $script[$i] ;
- $iniurl = $server[$i] . "/" . $url[$i] ;
- $path = $path[$i];
- $title = $title[$i];
- if ( $idxf[$i] =~ /^[yY]/ ) {
- $GLIMPSEIDX_OPT = $GLIMPSEIDX_OPT . " -o";
- }
- if ( $idxn[$i] =~ /^[yY]/ ) {
- $GLIMPSEIDX_OPT = $GLIMPSEIDX_OPT . " -n";
- }
- $| = 1;
- chdir $path || die "Cannot chdir to $path to build indices: $!\n";
- open(TEMPLATE,$TEMPLATE) || die "Cannot open index template file ".
- "$TEMPLATE: $!\n";
- $outid = "FILE000";
- &do_bd("",$title);
- close(TEMPLATE);
- print "Do you want to rebuild Glimpse index as well [no]?";
- $_ = <STDIN>;
- if ( /^[yY]/ ) {
- # unlink <.glimpse_[^i]*>;
- $cmd = "$GLIMPSEIDX_LOC $GLIMPSEIDX_OPT -H . .";
- system($cmd) && die "Cannot execute '$cmd': $!\n";
- }
- }
-
- sub do_bd {
- local($relpath,$title) = @_;
- local($file,$thisdir,$desc,$dirfiles,$dirsize,$totfiles,$totsize);
- local(%desc,$header,$OUT,$DIR,$fileshere,$dirshere);
- $totfiles = 0;
- $totsize = 0;
- $thisdir = `pwd`;
- chop $thisdir;
- undef $dirshere;
- undef $fileshere;
-
- $OUT = $outid;
- $DIR = $outid;
- $outid++;
- open($OUT,">$HTMLINDEX") || die "Cannot open file ".
- "$thisdir/$HTMLINDEX for writing: $!\n";
- print $OUT "\<HEAD>\<TITLE>$title\</TITLE></HEAD>\n";
- print $OUT "\<BODY>\<H1>$title\</H1>\n";
- &put_segment($OUT,"PROLOG");
- # slurp description file into array desc
- if (open(DESC,$DESCFILE)) {
- descline: while (<DESC>) {
- # print verbatim any lines beginning with @
- if (s/^\@//) {
- print;
- next descline;
- }
- chop;
- ($file,$desc) = split(/\t+/);
- next descline unless $file =~ /^\w/;
- $desc{$file} = $desc;
- }
- close(DESC);
- }
- opendir($DIR,".");
- file: while ($file=readdir($DIR)) {
- next if $file =~ /^\./;
- next if $file eq $HTMLINDEX;
- local($dev,$ino,$mode,$nlinsk,$uid,$gid,$rdev,$size) =
- stat($file);
- if (-d $file) {
- print "subdirectory $path/$file\n";
- chdir $file || next file;
- $desc = $desc{$file};
- if ($desc) {
- $header = $desc;
- ($dirfiles,$dirsize) =
- &do_bd("$relpath/$file",$desc);
- } else {
- # no description - make it up
- $desc = "$title/$file";
- ($dirfiles,$dirsize) =
- &do_bd("$relpath/$file",$desc);
- $header = "Directory '$file' (";
- $header .= "$dirfiles files, " if $dirfiles;
- $header .= "total $dirsize bytes)";
- }
- $totfiles += $dirfiles;
- $totsize += $dirsize;
- chdir $thisdir;
- $dirshere .= "<li><a href=\"".
- "$file/$HTMLINDEX\">$header</a>\n";
- } else {
- $totfiles += 1;
- $totsize += $size;
- $header = $desc{$file};
- $header = "$file ($size bytes)" unless $header;
- $fileshere .= "<li><a href=\"$file\">".
- "$header</a>\n";
- }
- }
- closedir($DIR);
- if ($dirshere) {
- &put_segment($OUT,"PREDIR");
- print $OUT $dirshere;
- &put_segment($OUT,"POSTDIR");
- }
- &put_segment($OUT,"FORM");
- if ($fileshere) {
- &put_segment($OUT,"PREFILE");
- print $OUT $fileshere;
- &put_segment($OUT,"POSTFILE");
- }
- &put_segment($OUT,"EPILOG");
- close($OUT);
- return ($totfiles+1,$totsize);
- }
-
- sub put_segment {
- local($OUT,$label) = @_;
- local($_,$flag);
- seek(TEMPLATE,0,0);
- $flag = 0;
- line: while (<TEMPLATE>) {
- next if /^\#/;
- if (/^\@$label/) {
- $flag = 1;
- next line;
- }
- last line if $flag && /^\@/;
- next line unless $flag;
- s/\$\w[\w_]*/$&/gee;
- print $OUT $_;
- }
- }
-